package game.windows;

//import game.helper.HelperSlotsBunker;
import game.shared.Constants;
import game.shared.Resources;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Buttons;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector2;

public class Bunker extends Form{

	TextureRegion textureBunker, slotsLeft, slotsRight;
	BitmapFont font;
	String price;
	int chooseTab;
//	int chooseRow;
//	int chooseCol;
	Items tempItem = null;
	Button btMenu;
	ToggleButton tgTab;
	Button btBuy;
	public static String information;
	public Bunker() {
		textureBunker = Resources.getTextureRegion(Resources.BUNKER);
		slotsLeft = Resources.getTextureRegion(Resources.SLOTS_LEFT);
		slotsRight = Resources.getTextureRegion(Resources.SLOTS_RIGHT);
		font = new BitmapFont();
		information = "Hello";
		price = "";
		chooseTab = 1;
		btMenu = new Button(0, Constants.FUNCTION_CODE_MENU, Resources.getTextureRegion(Resources.MENU_MENU), Resources.getTextureRegion(Resources.MENU_MENU_2));
		btMenu.setXY(Constants.SCREEN_WIDTH - btMenu.width- 10, Constants.SCREEN_HEIGHT - btMenu.height - 10);
		
		tgTab = new ToggleButton(Constants.FUNCTION_CODE_TG_TAB, Resources.getTextureRegion(Resources.TG_TAB_1), Resources.getTextureRegion(Resources.TG_TAB_2));
		tgTab.setXY(Constants.SCREEN_WIDTH - tgTab.width- 10, Constants.SCREEN_HEIGHT - tgTab.height - 50);
		
		btBuy = new Button(0, Constants.FUNCTION_CODE_BUY, Resources.getTextureRegion(Resources.BUTTON_BUY_1), Resources.getTextureRegion(Resources.BUTTON_BUY_2));
		btBuy.setXY(Constants.SCREEN_WIDTH - btBuy.width - 15, 10);
		
		addItems();
		initParameter();
	}
	
	@Override
	public void update() {
		btMenu.update();
		tgTab.update();
		btBuy.update();
		if (chooseTab != 5){
			this.update(0);
			this.update(chooseTab);
		}
		dispath();
	}

	@Override
	public void render(SpriteBatch sb) {
		if(bDrawWatermark)
			sb.draw(watermark, 0, 0, Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT);
		sb.draw(textureBunker, 0, 0, Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT);
		
		btMenu.render(sb);
		tgTab.render(sb);
		btBuy.render(sb);
		
		if(chooseTab != 5){
			sb.draw(slotsLeft, 27, 39, slotsLeft.getRegionWidth(), slotsLeft.getRegionHeight());
			sb.draw(slotsRight, 267, 87, slotsRight.getRegionWidth(), slotsRight.getRegionHeight());
			this.render(0, sb);
			this.render(chooseTab, sb);
		}
		
		font.setColor(Color.BLUE);
		font.draw(sb, String.valueOf(Constants.HP)+ "/"+String.valueOf(Constants.HP_MAX), 55, 250);
		font.draw(sb, String.valueOf(Constants.MANA)+ "/"+String.valueOf(Constants.MANA_MAX), 155, 250);
		font.draw(sb, String.valueOf(Constants.GOLD), 310, 250);
		font.setColor(Color.WHITE);
		font.draw(sb, information, 35, 290);//information in information form;
		font.draw(sb, price, 345, 28);
		
		
	}
	
	private void addItems(){
		
		Button btSell = new Button(0, Constants.FUNCTION_CODE_SELL, Resources.getTextureRegion(Resources.BUTTON_SELL_1), Resources.getTextureRegion(Resources.BUTTON_SELL_2));
		btSell.setXY(168, 10);
		listItems.add(btSell);
		
		Button btTab_1 = new Button(0, Constants.FUNCTION_CODE_TAB_1, Resources.getTextureRegion(Resources.TAB_1), Resources.getTextureRegion(Resources.TAB_1_2));
		btTab_1.setXY(270, 40);
		listItems.add(btTab_1);
		
		Button btTab_2 = new Button(0, Constants.FUNCTION_CODE_TAB_2, Resources.getTextureRegion(Resources.TAB_2), Resources.getTextureRegion(Resources.TAB_2_2));
		btTab_2.setXY(320, 40);
		listItems.add(btTab_2);
		
		Button btTab_3 = new Button(0, Constants.FUNCTION_CODE_TAB_3, Resources.getTextureRegion(Resources.TAB_3), Resources.getTextureRegion(Resources.TAB_3_2));
		btTab_3.setXY(370, 40);
		listItems.add(btTab_3);
		
		Button btTab_4 = new Button(0, Constants.FUNCTION_CODE_TAB_4, Resources.getTextureRegion(Resources.TAB_4), Resources.getTextureRegion(Resources.TAB_4_2));
		btTab_4.setXY(420, 40);
		listItems.add(btTab_4);
		//Items(tab, way, col, row, function, ...)
		Items itHp_1 = new Items(listItems, 1, 1, 0, 0, Constants.FUNCTION_CODE_HP_1, Resources.getTextureRegion(Resources.HP_1), Resources.getTextureRegion(Resources.HP_1), 10, 5, 10);
		listItems.add(itHp_1);
		Items itHp_2 = new Items(listItems, 1, 1, 1, 0, Constants.FUNCTION_CODE_HP_2, Resources.getTextureRegion(Resources.HP_2), Resources.getTextureRegion(Resources.HP_2), 20 , 10, 20);
		listItems.add(itHp_2);
		Items itHp_3 = new Items(listItems, 1, 1, 2, 0, Constants.FUNCTION_CODE_HP_3, Resources.getTextureRegion(Resources.HP_3), Resources.getTextureRegion(Resources.HP_3), 50, 25, 50);
		listItems.add(itHp_3);
		Items itHp_4 = new Items(listItems, 1, 1, 3, 0, Constants.FUNCTION_CODE_HP_4, Resources.getTextureRegion(Resources.HP_4), Resources.getTextureRegion(Resources.HP_4), 100, 50, 100);
		listItems.add(itHp_4);
		Items itMana_1 = new Items(listItems, 2, 1, 0, 0, Constants.FUNCTION_CODE_MANA_1, Resources.getTextureRegion(Resources.MANA_1), Resources.getTextureRegion(Resources.MANA_1), 10, 5, 10);
		listItems.add(itMana_1);
		Items itMana_2 = new Items(listItems, 2, 1, 1, 0, Constants.FUNCTION_CODE_MANA_2, Resources.getTextureRegion(Resources.MANA_2), Resources.getTextureRegion(Resources.MANA_2), 20, 10, 20);
		listItems.add(itMana_2);
		Items itMana_3 = new Items(listItems, 2, 1, 2, 0, Constants.FUNCTION_CODE_MANA_3, Resources.getTextureRegion(Resources.MANA_3), Resources.getTextureRegion(Resources.MANA_3), 50, 25, 50);
		listItems.add(itMana_3);
		Items itMana_4 = new Items(listItems, 2, 1, 3, 0, Constants.FUNCTION_CODE_MANA_4, Resources.getTextureRegion(Resources.MANA_4), Resources.getTextureRegion(Resources.MANA_4), 100, 50, 100);
		listItems.add(itMana_4);
		Items itGemRed_1 = new Items(listItems, 3, 1, 0, 0, Constants.FUNCTION_CODE_GEM_RED_1, Resources.getTextureRegion(Resources.GEM_RED_1), Resources.getTextureRegion(Resources.GEM_RED_1), 10, 5, 10);
		listItems.add(itGemRed_1);
		Items itGemRed_2 = new Items(listItems, 3, 1, 1, 0, Constants.FUNCTION_CODE_GEM_RED_2, Resources.getTextureRegion(Resources.GEM_RED_2), Resources.getTextureRegion(Resources.GEM_RED_2), 20, 10, 20);
		listItems.add(itGemRed_2);
		Items itGemRed_3 = new Items(listItems, 3, 1, 2, 0, Constants.FUNCTION_CODE_GEM_RED_3, Resources.getTextureRegion(Resources.GEM_RED_3), Resources.getTextureRegion(Resources.GEM_RED_3), 50, 25, 50);
		listItems.add(itGemRed_3);
		Items itGemRed_4 = new Items(listItems, 3, 1, 3, 0, Constants.FUNCTION_CODE_GEM_RED_4, Resources.getTextureRegion(Resources.GEM_RED_4), Resources.getTextureRegion(Resources.GEM_RED_4), 100, 50, 100);
		listItems.add(itGemRed_4);
		Items itGemBlue_1 = new Items(listItems, 4, 1, 0, 0, Constants.FUNCTION_CODE_GEM_BLUE_1, Resources.getTextureRegion(Resources.GEM_BLUE_1), Resources.getTextureRegion(Resources.GEM_BLUE_1), 10, 5, 10);
		listItems.add(itGemBlue_1);
		Items itGemBlue_2 = new Items(listItems, 4, 1, 1, 0, Constants.FUNCTION_CODE_GEM_BLUE_2, Resources.getTextureRegion(Resources.GEM_BLUE_2), Resources.getTextureRegion(Resources.GEM_BLUE_2), 20, 10, 20);
		listItems.add(itGemBlue_2);
		Items itGemBlue_3 = new Items(listItems, 4, 1, 2, 0, Constants.FUNCTION_CODE_GEM_BLUE_3, Resources.getTextureRegion(Resources.GEM_BLUE_3), Resources.getTextureRegion(Resources.GEM_BLUE_3), 50, 25, 50);
		listItems.add(itGemBlue_3);
		Items itGemBlue_4 = new Items(listItems, 4, 1, 3, 0, Constants.FUNCTION_CODE_GEM_BLUE_4, Resources.getTextureRegion(Resources.GEM_BLUE_4), Resources.getTextureRegion(Resources.GEM_BLUE_4), 100, 50, 100);
		listItems.add(itGemBlue_4);
		
		//Item co  san trong ruong do.
	}
	
	@Override
	public void dispath() {
		switch (Constants.get_RETURN_CODE()) {
		case Constants.FUNCTION_CODE_MENU:
			Constants.set_RETURN_CODE(Constants.FUNCTION_CODE_MENU);
			break;	
		case Constants.FUNCTION_CODE_TAB_1:
			information = "You choose tab 1";
			price = "buy/sell";
			chooseTab = 1;
			break;
		case Constants.FUNCTION_CODE_TAB_2:
			information = "You choose tab 2";
			price = "buy/sell";
			chooseTab = 2;
			break;
		case Constants.FUNCTION_CODE_TAB_3:
			information = "You choose tab 3";
			price = "buy/sell";
			chooseTab = 3;
			break;
		case Constants.FUNCTION_CODE_TAB_4:
			information = "You choose tab 4";
			price = "buy/sell";
			chooseTab = 4;
			break;
		case Constants.FUNCTION_CODE_HP_1:
			information = "Increase 10 HP";
			price = "10/5";
			break;
		case Constants.FUNCTION_CODE_HP_2:
			information = "Increase 20 HP";
			price = "20/10";
			break;
		case Constants.FUNCTION_CODE_HP_3:
			information = "Increase 50 HP";
			price = "50/25";
			break;
		case Constants.FUNCTION_CODE_HP_4:
			information = "Increase 100 HP";
			price = "100/50";
			break;
		case Constants.FUNCTION_CODE_MANA_1:
			information = "Increase 10 MANA";
			price = "10/5";
			break;
		case Constants.FUNCTION_CODE_MANA_2:
			information = "Increase 20 MANA";
			price = "20/10";
			break;
		case Constants.FUNCTION_CODE_MANA_3:
			information = "Increase 50 MANA";
			price = "50/25";
			break;
		case Constants.FUNCTION_CODE_MANA_4:
			information = "Increase 100 MANA";
			price = "100/50";
			break;
		case Constants.FUNCTION_CODE_GEM_RED_1:
			information = "Increase 10 HP MAX; Regen 1HP/s";
			price = "10/5";
			break;
		case Constants.FUNCTION_CODE_GEM_RED_2:
			information = "Increase 20 HP MAX; Regen 1HP/s";
			price = "20/10";
			break;
		case Constants.FUNCTION_CODE_GEM_RED_3:
			information = "Increase 50 HP MAX; Regen 1HP/s";
			price = "50/25";
			break;
		case Constants.FUNCTION_CODE_GEM_RED_4:
			information = "Increase 100 HP MAX; Regen 1HP/s";
			price = "100/50";
			break;
		case Constants.FUNCTION_CODE_GEM_BLUE_1:
			information = "Increase 10 MANA MAX; Regen 1MANA/s";
			price = "10/5";
			break;
		case Constants.FUNCTION_CODE_GEM_BLUE_2:
			information = "Increase 20 MANA MAX; Regen 1MANA/s";
			price = "20/10";
			break;
		case Constants.FUNCTION_CODE_GEM_BLUE_3:
			information = "Increase 50 MANA MAX; Regen 1MANA/s";
			price = "50/25";
			break;
		case Constants.FUNCTION_CODE_GEM_BLUE_4:
			information = "Increase 100 MANA MAX; Regen 1MANA/s";
			price = "100/50";
			break;
		case Constants.FUNCTION_CODE_BUY:
			information = "You press buy";
			for(int i=0; i<listItems.size(); i++)
				if (listItems.get(i).id == Constants.ID_ITEMS_CHOOSE)
					if (listItems.get(i) instanceof Items){
						tempItem = (Items)listItems.get(i);
						tempItem.actionWhenBuy();
					}
			break;
		case Constants.FUNCTION_CODE_SELL:
			information = "You press sell";
			for (int i=0; i<listItems.size(); i++)
				if (listItems.get(i).id == Constants.ID_ITEMS_CHOOSE)
					if (listItems.get(i) instanceof Items){
						tempItem = (Items)listItems.get(i);
						tempItem.actionWhenSell();
					}
			break;
		case Constants.FUNCTION_CODE_TG_TAB:
			if (Constants.get_RETURN_VALUE() == 0){
				chooseTab = 1;
				information = "Tab 1: Buy and sell items";
			}
			else{
				chooseTab = 5;
				information = "Tab 2: Upgrade lightning, snow, fire...";
			}
			break;
		}
	}
	
	private void initParameter(){
		Constants.HP = Constants.HP_DEFAULT;
		Constants.MANA = Constants.MANA_DEFAULT;
		Constants.HP_MAX = Constants.HP_MAX_DEFAULT;
		Constants.MANA_MAX = Constants.MANA_MAX_DEFAULT;
	}
}
